home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11719 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  78 lines

  1. Path: dte.detroitedison.com!news
  2. From: "mccardellc@detroitedison.com" <mccardellc@detroitedison.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pointer to interrupt method in BC 4.52
  5. Date: 14 Mar 1996 23:32:24 GMT
  6. Organization: Detroit Edison
  7. Message-ID: <4iaaa8$oc6@news.deco.com>
  8. References: <4i9sho$3mj@masala.cc.uh.edu>
  9. NNTP-Posting-Host: 162.9.222.240
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; U; 16bit)
  14.  
  15. pmn12564@Bayou.UH.EDU (pat neff) wrote:
  16. >    I have a class in which one of the methods is an interrupt.  Since I need
  17. >to hook the interrupt into the interrupt table, I need a pointer to it.     
  18. >Something like:
  19. >
  20. >class myobject {
  21. >
  22. >void interrupt myinterrupt(...);
  23. >void dohook ();
  24. >}
  25. >
  26. >void interrupt myobject::myinterrupt (...)
  27. >{
  28. >  // actuall interrupt code here
  29. >}
  30. >
  31. >void myobject::dohook ()
  32. >{
  33. >   setvect (0x??, this->myinterrupt);
  34. >}
  35. >
  36. >     This compiler complains about the line with SETVECT saying I need to
  37. >call or take the address of the interrupt function.  I am trying to take the
  38. >address of course.  I have tried everything, but NO LUCK!  Can anyone out     
  39. >there help me? 
  40. >
  41.  
  42.  
  43. The only way to have a member function called by an interrupt is to
  44. make it a static function.
  45.  
  46. Static functions are functions which are available to a class without 
  47. instances of the class being declared.
  48.  
  49. The code would look like this:
  50.  
  51. class myobject {
  52. public:
  53. static void interrupt myinterrupt(...);
  54.  
  55. void dohook ();
  56. }
  57.  
  58. void interrupt myobject::myinterrupt (...)
  59. {
  60.   // actuall interrupt code here
  61. }
  62.  
  63. void myobject::dohook ()
  64. {
  65.    setvect (0x??, myobject::myinterrupt);
  66. }
  67.  
  68. Note: You can't access the 'this' pointer within a static object, 
  69. therefore your member variables are NOT accessable in the interrupt 
  70. function.
  71.  
  72. Good luck!
  73.  
  74.  
  75. Clifford McCardell
  76.  
  77.  
  78.